<template>
	<view class="container">
		<my-tab :list="list1" bgColor="#fff" :current="currentIndex" @itemClick='itemClick'></my-tab>
		<view class="lists" v-if="list.length>0">
			<view class="item" v-for="(item,index) in list" :key="index" @click="toLog(item)">
				<view class="left">{{item.name}}</view>
				<view class="right">
					<view class="number">数量：{{item.money}}</view>
					<view class="right-btns" :class="{'right-btns-center':currentIndex==1}">
						<button size="mini" class="right-btn" v-if="currentIndex==0" @click.stop="jump(item,1)">出售</button>
						<button size="mini" class="right-btn" :disabled="item.feed_status==3" @click.stop="feed(item)" v-else>领取</button>
						<button size="mini" class="right-btn default" v-if="currentIndex==0"  @click.stop="jump(item,2)">转让</button>
					</view>
				</view>
			</view>
			<u-loadmore :status="hasMore?'loading':'nomore'" />
		</view>
		<view class="empty-container" v-else>
			<u-empty text="暂无相关数据" :icon="emptyIcon"></u-empty>
		</view>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				list1: [{
					name: '已拥有',
				}, {
					name: '待领取',
				}],
				user:'',
				currentIndex: 0,
				list:[],
				emptyIcon:'https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/common/empty.png',
				hasMore:true,
				pageIndex:1,
			};
		},
		onReachBottom() {
			if(this.hasMore){
				this.pageIndex++
				this.get_my_wallet_list()
			}
		},
		methods: {
			//获取用户信息
			async get_user_info(){
				const data = await _this.$post('api/UserInfo')
				if(data.code==200){
					this.user=data.data.user
				}else{
					this.$u.toast(data.msg)
				}
			},
			toLog(item){
				if(_this.currentIndex==1){
					return
				}
				uni.navigateTo({
					url:`/pages/center/my-wallet-log?u_wid=${item.id}`
				})
			},
			itemClick(index){
				_this.currentIndex=index
				_this.pageIndex=1
				_this.list=[]
				_this.get_my_wallet_list()
			},
			async feed(item){
				let params={
					order_id:item.order_id,
					type:2
				}
				const data = await _this.$post('api/ry_dd_feed',params)
				if (data.code == 200) {
					this.$u.toast(data.msg)
					item.feed_status=3
				} else {
					this.$u.toast(data.msg)
				}
			},
			jump(item,type){
				if(_this.user.is_set_paypwd==0){
					uni.$u.toast('请先设置交易密码');
					setTimeout(()=>{
						uni.navigateTo({
							url:'/pages/center/paypwd'
						})
					},2000)
					return
				}
				if(type==1){
					uni.navigateTo({
						url:`/pages/center/my-wallet-sell?id=${item.id||0}`
					})
				}else{
					uni.navigateTo({
						url:`/pages/center/my-wallet-transfer?id=${item.id||0}`
					})
				}
			},
			//获取余额明细数据
			async get_my_wallet_list() {
				const params = {
					type: this.currentIndex,
					pageIndex: this.pageIndex,
					pageSize: 20,
				}
				const data = await _this.$post('api/get_my_wallet_list',params)
				if(data.code==200){
					this.list.push(...data.data.list)
					this.hasMore=data.data.list.length>=20
				}else{
					this.hasMore=false
				}
			}
		},
		onLoad(e) {
			_this = this;
			_this.get_my_wallet_list()
		},
		onShow() {
			_this.get_user_info()
		},
		components: {}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 0;
		.lists{
			padding: 20rpx 30rpx 0 30rpx;
			.item{
				@include flex-box(row);
				background: #fff;
				border-radius: 20rpx;
				height: 200rpx;
				overflow: hidden;
				margin-bottom: 20rpx;
				.left{
					color: #fff;
					height: 100%;
					font-weight: 500;
					font-size: 30rpx;
					width: 200rpx;
					@include flex-box(row,center,center);
					background: url('https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/user/money-bg.png') center/100% 100% no-repeat;
				}
				.right{
					flex: 1;
					@include flex-box(row,space-between,center);
					padding: 30rpx;
					.right-btns{
						height: 100%;
						@include flex-box(column,space-between,center);
						.right-btn{
							background: $theme-color;
							color: #fff;
							padding: 0;
							height: 50rpx;
							line-height: 46rpx;
							border-radius: 30rpx;
							border: 2rpx solid $theme-color;
							width: 130rpx;
							font-weight: 500;
							&[disabled]{
								background: rgba($theme-color, 0.5);
								border: none;
								line-height: 50rpx;
							}
						}
						.default{
							background: none;
							color: $color-080524;
							border-color: $color-919191;
						}
					}
					.right-btns-center{
						justify-content: center;
					}
				}
			}
		}
	}
</style>
